package com.huawei.common;

import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * @Author LF
 * projectName:vue-cli
 * description:
 * time:2025-04-25 23:01
 */
@Getter
@Setter
@NoArgsConstructor
public class BaseResult<T> {
    /**
     * 状态码
     */
    private int code;

    /**
     * 消息内容
     */
    private String message;

    /**
     * 返回的数据
     */
    private T data;

    public BaseResult(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public BaseResult(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 示例：成功返回的方法
    public static <T> BaseResult<T> success(T data) {
        return new BaseResult<>(BusinessCode.SUCCESS.getCode(), BusinessCode.SUCCESS.getMessage(), data);
    }

    public static BaseResult success() {
        return new BaseResult<>(BusinessCode.SUCCESS.getCode(), BusinessCode.SUCCESS.getMessage());
    }

    // 示例：失败返回的方法
    public static <T> BaseResult<T> fail(String message) {
        return new BaseResult<>(BusinessCode.INTERNAL_SERVER_ERROR.getCode(),
                BusinessCode.INTERNAL_SERVER_ERROR.getMessage(), null);
    }

}
